//
//  CXHRewardVideoViewController.m
//  CXHAdSDK_Example
//
//  Created by 陈坤 on 2025/3/20.
//  Copyright © 2025 华资融创. All rights reserved.
//

#import "CXHRewardVideoViewController.h"
#import <CXHAdSDK-Core/CXHAdSDK.h>
#import <CXHAdSDK-Core/CXHAdSDKRewardVideoAd.h>
#import <CXHAdSDK-Kit/CXHUtilsKit.h>

@interface CXHRewardVideoViewController ()<CXHAdSDKRewardVideoAdDelegate>

@property (nonatomic, strong) CXHAdSDKRewardVideoAd *rewardVideoAd;

@end

@implementation CXHRewardVideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    UIBarButtonItem *itemLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onCancelClicked:)];
    self.navigationItem.leftBarButtonItem = itemLeft;
    
    UIButton *btn2 = [UIButton new];
    btn2.backgroundColor = [UIColor orangeColor];
    btn2.layer.cornerRadius = 20;
    
    btn2.frame = CGRectMake((kCXHScreenWidth -200)/2, kCXHTopBarHeight + 100, 200, 40);
    [btn2 setTitle:@"加载激励视频广告" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:btn2];
    [btn2 addTarget:self action:@selector(loadRewardVideoAd) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)onCancelClicked:(id)sender {
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

- (void)loadRewardVideoAd{
    self.rewardVideoAd = [[CXHAdSDKRewardVideoAd alloc]init];
    self.rewardVideoAd.delegate = self;
    self.rewardVideoAd.controller = self;
    self.rewardVideoAd.posId = @"14335012";
    self.rewardVideoAd.videoMuted = YES;
    [self.rewardVideoAd loadAdData];
}

#pragma mark - CXHAdSDKRewardVideoAdDelegate
/**
 广告数据加载成功回调

 @param rewardedVideoAd CXHAdSDKRewardVideoAd 实例
 */
- (void)CXH_rewardVideoAdDidLoad:(CXHAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"rewardedVideoAd===%s",__func__);
    [self.rewardVideoAd showRewardVideoAdFromRootViewController:self];
}

///**
// 视频数据下载成功回调，已经下载过的视频会直接回调
//
// @param rewardedVideoAd CXHAdSDKRewardVideoAd 实例
// */
//- (void)CXH_rewardVideoAdVideoDidLoad:(CXHAdSDKRewardVideoAd *)rewardedVideoAd;

/**
 视频播放页即将展示回调

 @param rewardedVideoAd CXHAdSDKRewardVideoAd 实例
 */
- (void)CXH_rewardVideoAdWillVisible:(CXHAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"rewardedVideoAd===%s",__func__);
}

/**
 视频广告曝光回调

 @param rewardedVideoAd CXHAdSDKRewardVideoAd 实例
 */
- (void)CXH_rewardVideoAdDidExposed:(CXHAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"rewardedVideoAd===%s",__func__);
}

/**
 视频广告曝光上报回调（只会回调一次）

 @param rewardedVideoAd CXHAdSDKRewardVideoAd 实例
 */
- (void)CXH_rewardVideoAdDidExposeReport:(CXHAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"rewardedVideoAd===%s",__func__);
}

/**
 视频播放页关闭回调

 @param rewardedVideoAd CXHAdSDKRewardVideoAd 实例
 */
- (void)CXH_rewardVideoAdDidClose:(CXHAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"rewardedVideoAd===%s",__func__);
}

/**
 视频广告信息点击回调（可能回调多次）

 @param rewardedVideoAd CXHAdSDKRewardVideoAd 实例
 */
- (void)CXH_rewardVideoAdDidClicked:(CXHAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"rewardedVideoAd===%s",__func__);
}

/**
 视频广告信息点击上报回调（只会回调一次）

 @param rewardedVideoAd CXHAdSDKRewardVideoAd 实例
 */
- (void)CXH_rewardVideoAdDidClickReport:(CXHAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"rewardedVideoAd===%s",__func__);
}

/**
 视频广告各种错误信息回调

 @param rewardedVideoAd CXHAdSDKRewardVideoAd 实例
 @param error 具体错误信息
 */
- (void)CXH_rewardVideoAd:(CXHAdSDKRewardVideoAd *)rewardedVideoAd didFailWithError:(NSError *)error{
    NSLog(@"rewardedVideoAd===%s",__func__);
}

/**
 视频广告播放达到激励条件回调

 @param rewardedVideoAd CXHAdSDKRewardVideoAd 实例
 @param info 包含此次广告行为的一些信息
 */
- (void)CXH_rewardVideoAdDidRewardEffective:(CXHAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"rewardedVideoAd===%s",__func__);
}

/**
 视频广告视频播放完成

 @param rewardedVideoAd CXHAdSDKRewardVideoAd 实例
 */
- (void)CXH_rewardVideoAdDidPlayFinish:(CXHAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"rewardedVideoAd===%s",__func__);
}

@end
